/**
 * 
 */
package com.kingcore.director.resourcemaster.dao.impl;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.kingcore.director.DirectorConstants;
import com.kingcore.director.base.dao.impl.DirectorDaoJdbcImpl;
import com.kingcore.director.resourcemaster.dao.ResourceMasterDao;

/**
 * @author Zeven
 *
 */
public class ResourceMasterDaoImpl extends DirectorDaoJdbcImpl
		implements ResourceMasterDao {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 同步收藏FMT_FavoriteFiles、复制FMT_FileCopy、备份FMT_FileBackup的目录。
	 */
	@Override
	public void synchResourceUri(String fileUri, String newUri)
			throws Exception {
		List<String> sqls = new ArrayList<String>();
		String fileName = "";
		String fileExtName = "";
		if (newUri.endsWith( File.separator) ) {  //都不以分隔符结尾
			newUri = newUri.substring(0, newUri.length()-1);
		}
		fileName = newUri.substring(newUri.lastIndexOf(File.separator)+1, newUri.length() );
		
		if (fileName!=null && fileName.indexOf(".")>0) {
			fileExtName = fileName.substring(fileName.lastIndexOf(".")); //return as ".txt"
		}
		System.out.println( this.getDataSourceName()  );
		sqls.add("Update "+DirectorConstants.FMT_FavoriteFiles+" Set Location='"+newUri+"'"+
						" ,Namee='"+fileName+"'" +
						" ,Typee='"+fileExtName+"'" +
					" Where Location='"+fileUri+"'");
		sqls.add("Update "+DirectorConstants.FMT_FileCopy+" Set PATH='"+newUri+"'"+
					" Where PATH='"+fileUri+"'");
		sqls.add("Update "+DirectorConstants.FMT_FileBackup+" Set PATH='"+newUri+"'"+
					" Where PATH='"+fileUri+"'");
		this.executeBatch(sqls);
		
	}

}
